<?php

namespace App\Repositories;

use App\Exceptions\BasicException;

class UserUntieBanClassifyRepository
{
    /**
     * @Desc:解开封禁分类列表
     * @param $param
     * @return mixed
     * @author: shiquan
     * @Time: 2022/11/3 15:52
     */
    public function list($param)
    {
        $list = app('model_user_ban_classify')->where('type', 1)
            ->orderBy('id', 'desc')
            ->paginate($param['page_size'] ?? 10, ['*'], '', $param['page'] ?? 1);
        return $list;
    }

    /**
     * @Desc:新增
     * @param $params
     * @return mixed
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:52
     */
    public function create($params)
    {
        $data = [
            'title' => $params['title'],
            'type' => 1
        ];
        $res = app('model_user_ban_classify')->create($data);
        if ($res){
            return $res;
        } else {
            throw new BasicException(0, '添加失败');
        }
    }

    /**
     * @Desc:详情
     * @param $param
     * @return mixed
     * @author: shiquan
     * @Time: 2022/11/3 15:53
     */
    public function info($param)
    {
        $info = app('model_user_ban_classify')
            ->where('id', $param['id'])
            ->first();
        return $info;
    }

    /**
     * @Desc:更新
     * @param $params
     * @return mixed
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:53
     */
    public function update($params)
    {
        $id = $params['id'];
        $data = [
            'title' => $params['title'],
            'type' => 1,
        ];
        $res = app('model_user_ban_classify')->where('id', $id)->update($data);
        if ($res){
            return $res;
        } else {
            throw new BasicException(0, '编辑失败');
        }
    }

    /**
     * @Desc:删除
     * @param $param
     * @return mixed
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:53
     */
    public function delete($param)
    {
        $res = app('model_user_ban_classify')->whereIn('id', $param['ids'])->delete();
        if ($res){
            return $res;
        } else {
            throw new BasicException(0, '删除失败');
        }
    }
}
